package com.example.noval.ui.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.noval.R
import com.example.noval.db.mode.ContentResp
import com.example.noval.db.mode.TextPage

/**
 * @Description
 * @Author zzl
 * @Date 2024/3/28
 */
class ReadBookAdapter(private var dataList:List<ContentResp>):RecyclerView.Adapter<ReadBookAdapter.ReadBookViewHolder>() {

    private var itemClickListener: OnItemClickListener? = null


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReadBookViewHolder {

        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_read_book, parent, false)

        return ReadBookViewHolder(view)
    }

    override fun getItemCount(): Int {
            return dataList.size
        
    }

    override fun onBindViewHolder(holder: ReadBookViewHolder, position: Int) {
        holder.content.text=dataList[position].content
        holder.itemView.setOnClickListener(View.OnClickListener(){

            itemClickListener?.onItemClick(position)
        })
        
    }

    fun updateDataList(newData:List<ContentResp>) {
        dataList= newData
        notifyDataSetChanged()
    }
    
    public interface OnItemClickListener{
        fun onItemClick(position: Int)
    }
    public fun setOnItemClick(itemClickListener: OnItemClickListener){
        this.itemClickListener=itemClickListener
    }
    
    
    class ReadBookViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){

        val content: TextView =itemView.findViewById(R.id.text)

    }
    
    
    
    
   
}